package dcl.software.filesync.client;

import java.io.File;

public class ClientMain {
	public static void main(String[] args) {
		String token = login();
		uploadFile(new File("E:\\"), token);
	}
	private static String createAccount() {
		CreateUserDTO user = new CreateUserDTO();
		user.setUserName("ldloutsch");
		user.setPassword("testPassword");
		user.setConfirmedPassword("testPassword");
		user.setMacAddress(MacUtils.getMacAddress());
		user.setEmail("ldloutsch@gmail.com");
		String token = null;
		try {
			token = HttpsUtils.createAccount(user);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return token;
	}
	
	private static String login() {
		LoginUserDTO user = new LoginUserDTO();
		user.setUserName("ldloutsch");
		user.setPassword("testPassword");

		String token = null;
		try {
			token = HttpsUtils.login(user);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return token;
	}

	private static void uploadFile(File file, String token) {
		if (file.isDirectory()) {
			File[] listFiles = file.listFiles();
			for (File subFile : listFiles) {
				if (subFile.isDirectory())
					uploadFile(subFile, token);
				else {
					uploadIndividualFile(subFile, token);
				}
			}
		} else
			uploadIndividualFile(file, token);
	}

	private static void uploadIndividualFile(File file, String token) {
			try {
				HttpsUtils.uploadFile(file, token);
			} catch (Exception e) {
				e.printStackTrace();
			}
	}
}
